package com.itfreer.bpm.workflow.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.bpm.flow.api.IUserNextTask;
import com.itfreer.bpm.option.para.NextTaskInfo;
import com.itfreer.bpm.option.para.NextTaskType;
import com.itfreer.bpm.option.para.TaskInfo;
import com.itfreer.bpm.workflow.drive.IWorkFlowDrive;

/**
 * 获取下一个环节信息
 * @author gj
 *
 */
@Component
public class BpmNextTaskUtils {
	
	@Autowired(required=false)
	IUserNextTask userNextTask;
	/**
	 * 流程驱动服务
	 */
	@Autowired
	protected IWorkFlowDrive workFlowDrive;
	
	/**
	 * 获取下一个环节信息
	 * @param sexeid
	 * @param bpmkey
	 * @param taskdefid
	 * @param condition
	 * @return
	 */
	public NextTaskInfo getNextTaskInfo(String sexeid,String bpmkey,String taskdefid,Object entity) {
		NextTaskInfo nextTaskInfo= workFlowDrive.getNextTask(bpmkey, taskdefid);
		String condition="提交";
		if(userNextTask!=null) {
			nextTaskInfo=userNextTask.getNextTask(sexeid, bpmkey, taskdefid, condition, nextTaskInfo,entity);
		}
		return nextTaskInfo;
	}
	
	/**
	 * 读取退回节点信息
	 * @param sexeid
	 * @param bpmkey
	 * @param taskdefid
	 * @return
	 */
	public NextTaskInfo getRollBackTaskInfo(String sexeid,String bpmkey,String taskdefid,Object entity) {
		NextTaskInfo nextTaskInfo= workFlowDrive.getRollBackTask(bpmkey, taskdefid);
		String condition="退回";
		if(userNextTask!=null) {
			nextTaskInfo=userNextTask.getNextTask(sexeid, bpmkey, taskdefid, condition, nextTaskInfo,entity);
		}
		return nextTaskInfo;
	}
}
